package com.hsjk.szwj.module.pay.controller.app.order.vo;

import com.hsjk.szwj.module.pay.dal.dataobject.config.AbstractResp;
import com.hsjk.szwj.module.pay.dal.dataobject.order.PayOrderDO;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.time.LocalDateTime;

/**
 * @author chenjiawei
 * @desc 查询订单 响应参数
 * @Date 2023/08/24 18:08
 **/
@Data
public class QueryPayOrderRespVO extends AbstractResp {
    /**
     * 支付订单号
     */
    private Long payOrderId;

    /**
     * 商户号
     */
    private Long mchId;

    /**
     * 商户应用ID
     */
    private Long appId;

    /**
     * 商户订单号
     */
    private Long mchOrderId;

    /**
     * 支付接口代码
     */
    private Long ifId;

    /**
     * 支付方式代码
     */
    private String wayCode;

    /**
     * 支付金额,单位分
     */
    private Long amount;

    /**
     * 三位货币代码,人民币:cny
     */
    private String currency;

    /**
     * 支付状态: 0-订单生成, 1-支付中, 2-支付成功, 3-支付失败, 4-已撤销, 5-已退款, 6-订单关闭
     */
    private Integer state;

    /**
     * 客户端IP
     */
    private String clientIp;

    /**
     * 商品标题
     */
    private String subject;

    /**
     * 商品描述信息
     */
    private String body;

    /**
     * 渠道订单号
     */
    private String channelOrderNo;

    /**
     * 渠道支付错误码
     */
    private String errCode;

    /**
     * 渠道支付错误描述
     */
    private String errMsg;

    /**
     * 商户扩展参数
     */
    private String extParam;

    /**
     * 订单支付成功时间
     */
    private LocalDateTime successTime;

    /**
     * 创建时间
     */
    private LocalDateTime createTime;


    public static QueryPayOrderRespVO buildByPayOrder(PayOrderDO payOrder) {

        if (payOrder == null) {
            return null;
        }

        QueryPayOrderRespVO result = new QueryPayOrderRespVO();
        BeanUtils.copyProperties(payOrder, result);
        result.setSuccessTime(payOrder.getSuccessTime() == null
                ? null : payOrder.getSuccessTime());
        result.setCreateTime(payOrder.getCreateTime() == null
                ? null : payOrder.getCreateTime());
        return result;
    }
}
